import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_base/base/widget/base_get_builder.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/generated/assets.dart';

import 'package:flutter_base/utils/log/utils_log.dart';
import 'package:flutter_base/utils/test_result_component_util.dart';
import 'package:flutter_base/widgets/appbar/common_app_bar.dart';
import 'package:flutter_base/widgets/button/common_button.dart';
import 'package:flutter_base/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'test_result_normal_logic.dart';

class TestResultNormalPage extends StatelessWidget {
  TestResultNormalPage({super.key});

  final TestResultNormalLogic logic = Get.put(TestResultNormalLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<TestResultNormalLogic>(
      backgroundView: Positioned.fill(
          child: Container(
        decoration: const BoxDecoration(
            image: DecorationImage(
                image: AssetImage(
                  Assets.testResultNormalTopBg,
                ),
                fit: BoxFit.fitWidth,
                alignment: Alignment.topCenter)),
      )),
      builder: (controller) {
        return Stack(
          children: [
            Positioned.fill(
                child: SingleChildScrollView(
              controller: controller.scrollController,
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 16.w).copyWith(
                    top: 24.w + kToolbarHeight + ScreenUtil().statusBarHeight,
                    bottom: 60.w + ScreenUtil().bottomBarHeight),
                child: Column(
                  children: [
                    _buildAdvancedReportCard(),
                    SizedBox(height: 20.w),
                    Obx(() {
                      return Column(
                          children:
                              (logic.testDetail.value.result?.components ?? [])
                                  .map((item) {
                        clog('dakdakshd   ${item.toJson()}');
                        return TestResultComponentUtil.buildComponentByType(
                                item)
                            .marginOnly(bottom: 20.w);
                      }).toList());
                    }),
                  ],
                ),
              ),
            )),
            Positioned(
                bottom: ScreenUtil().bottomBarHeight,
                // bottom: ScreenUtil()(),
                right: 16.w,
                left: 16.w,
                child: CommonButton.expend(
                  title: 'Test again',
                  onClick: () {
                    // logic.startTest();
                  },
                )),
            Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: Obx(() {
                  return CommonAppBar(
                    title: 'Test Details',
                    leadingImageColor: logic.isDarkTitle.value
                        ? Colors.white
                        : AppColor.color0C0A09,
                    titleColor: logic.isDarkTitle.value
                        ? Colors.white
                        : AppColor.color0C0A09,
                    backgroundColor:
                        Colors.white.withOpacity(logic.appBarOpacity),
                    actions: [
                      GestureDetector(
                        child: Container(
                          width: 32.w,
                          height: 32.w,
                          decoration: const BoxDecoration(
                            color: Colors.white,
                            shape: BoxShape.circle,
                          ),
                          alignment: Alignment.center,
                          child: AutoImage(
                            Assets.commonShare,
                            width: 24.w,
                          ),
                        ),
                      ),
                      16.horizontalSpace,
                    ],
                  );
                }))
          ],
        );
      },
    );
  }

  Widget _buildAdvancedReportCard() {
    return Container(
      width: double.infinity,

      padding: EdgeInsets.all(16.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [


          // 标题
          Text(
            'Discover the real you',
            style: TextStyle(
              fontFamily: 'Outfit',
              fontSize: 28.sp,
              fontWeight: FontWeight.w700,
              color: const Color(0xFF0C0A09),
              letterSpacing: -1.5, // 添加负的letterSpacing来减小文字间距
            ),
          ),
          SizedBox(height: 6.w),
          // 描述
          Text(
            'Gain deeper insights into your inner traits through scientific personality assessments',
            style: TextStyle(
              fontFamily: 'Outfit',
              fontSize: 12.sp,
              color: const Color(0xFF7F909F),
            ),
          ),
        ],
      ),
    );
  }

}
